fix: Prevent context attributes from influencing judge template parsing#129
Open
jsonbailey wants to merge 4 commits intomainfrom
Open
fix: Prevent context attributes from influencing judge template parsing#129jsonbailey wants to merge 4 commits intomainfrom
jsonbailey wants to merge 4 commits intomainfrom
Conversation
Co-Authored-By: jbailey@launchdarkly.com <accounts@sidewaysgravity.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: jbailey@launchdarkly.com <accounts@sidewaysgravity.com>
… injection Co-Authored-By: jbailey@launchdarkly.com <accounts@sidewaysgravity.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1ad110e. Configure here.
Co-Authored-By: jbailey@launchdarkly.com <accounts@sidewaysgravity.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Requirements
Related issues
Addresses SEC-8020. Mirrors the fix applied in the Go server AI SDK (
go-server-sdkcommit3317871). A parallel PR has also been opened forlaunchdarkly/js-core.Describe the solution you've provided
The judge's
_interpolate_messagemethod previously usedchevron.render()(Mustache templating) for its second-pass interpolation of{{message_history}}and{{response_to_evaluate}}placeholders. This is vulnerable to template injection: attacker-controlled values resolved during pass 1 (e.g. Mustache delimiter-change tags like{{=[ ]=}}) would be interpreted as control syntax by the second Mustache pass, potentially blinding the judge to the actual content being evaluated.This PR replaces the Mustache-based interpolation with simple
str.replace()calls. Since the judge only ever substitutes two known placeholder strings, a full template engine is unnecessary, and literal string replacement is both safer and simpler.Note:
chevronis still used inclient.pyfor the first-pass template interpolation (which is expected behavior — pass 1 needs Mustache to resolve context variables).Describe alternatives you've considered
Additional context
Key items for review:
chevronimport removal from the judge module doesn't affect other code paths (it doesn't —chevronis only used inclient.pyfor pass 1).Updates since last revision
_interpolate_messagedocstring per reviewer feedback on the parallel JS PR — now a concise two-line summary instead of a verbose multi-line explanation.Link to Devin session: https://app.devin.ai/sessions/651e799b906748a4834bafefb4a3e3e5
Requested by: @jsonbailey
Note
Medium Risk
Changes judge prompt interpolation logic (and removes Mustache rendering) to mitigate a template-injection vector; could subtly alter how existing judge message templates with non-
{{word}}placeholders are rendered.Overview
Prevents template-injection in judge prompt construction by replacing
chevron.renderinJudge._interpolate_messagewith a regex-based substitution that only expands{{message_history}}and{{response_to_evaluate}}, treating other Mustache control syntax as literal text.Adds targeted regression tests covering delimiter changes, partials/comments/sections, repeated placeholders, and cross-placeholder injection to ensure attacker-controlled values cannot affect the second-pass interpolation.
Reviewed by Cursor Bugbot for commit e64c5d2. Bugbot is set up for automated code reviews on this repo. Configure here.